Skip to content

gh-148228: Enable error overlays in the REPL#148229

Open
johnslavik wants to merge 5 commits intopython:mainfrom
johnslavik:enable-error-overlays
Open

gh-148228: Enable error overlays in the REPL#148229
johnslavik wants to merge 5 commits intopython:mainfrom
johnslavik:enable-error-overlays

Conversation

@johnslavik
Copy link
Copy Markdown
Member

Small proof of concept for gh-148228. We can build on this further on.

@johnslavik johnslavik changed the title gh-148228: Enable error overlays gh-148228: Enable error overlays in the REPL Apr 8, 2026
@johnslavik johnslavik added the topic-repl Related to the interactive shell label Apr 9, 2026
Comment thread Lib/_pyrepl/commands.py
r.setpos_from_xy(x, new_y)


class down(MotionCommand):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What makes down special? Doesn't the up command has the same UX bug that down ? Don't we need something like

if r.bol() == 0:
    if r.historyi > 0:
        r.select_item(r.historyi - 1)
        return
    if r.pos == 0:
        r.error("start of buffer")
    else:
        r.pos = 0
    return

for the up version?

Comment thread Lib/_pyrepl/reader.py
t = THEME()
error_prefix = f"{t.error}{error_prefix}{t.reset}"
self.console.beep()
self.msg = error_prefix + msg
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am misreading this flow but if I am not wrong, the error() now embeds the escape sequences into self.msg. The message renderer at _render_message_lines slices by string length, not visible width. Then, len(message_line) counts the ANSI bytes (\x1b[1;31m ... \x1b[0m), so on narrow terminals (or long error messages) the slice boundary can land mid-escape, producing a truncated \x1b[ on one line and stray m on the next leaving the whole line un-colored or visually corrupted.

Comment thread Lib/_pyrepl/commands.py
Comment on lines +299 to +302
if r.pos == len(b):
r.error("end of buffer")
else:
r.pos = len(b)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have tests that cover both branches here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review DO-NOT-MERGE topic-repl Related to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants